package jsu.xxy.coffee3.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import jsu.xxy.coffee3.domain.OrderIdAndProduct;
import jsu.xxy.coffee3.domain.Ordered;
import jsu.xxy.coffee3.domain.Orderform;
import jsu.xxy.coffee3.domain.Orders;
import jsu.xxy.coffee3.mapper.OrderformMapper;
import jsu.xxy.coffee3.mapper.OrdersMapper;

import jsu.xxy.coffee3.service.impl.OrderformServiceImpl;
import org.apache.ibatis.annotations.Update;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/orderForm")
public class OrderformController {
    @Autowired
    OrderformMapper orderformMapper;
    @Autowired
    OrderformServiceImpl orderformService;
    @Autowired
    OrdersMapper ordersMapper;
    @GetMapping("/ordered")
    @Operation(summary = "以完成订单")
    public Page<Ordered> getOrdered(
            @RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize)
    {
        return orderformService.getOrdered(pageNo,pageSize);
    }

    @GetMapping("/ordering")
    @Operation(summary = "没完成订单")
    public Page<Ordered> getOrdering( @RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
                                      @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize){
        return orderformService.getOrdering(pageNo,pageSize);

    }
    @GetMapping("/orderByCid")
    @Operation(summary = "顾客所有订单")
    public List<Ordered> getOrdering(@RequestParam Integer cid){
        return orderformService.getOrderByCid(cid);
    }
    @PostMapping("/changeStatue/{oid}")
    @Operation(summary = "修改订单状态")
    public boolean changStatue(@PathVariable int oid){
//        return orderformMapper.changeStatue(oid)>0;
        return orderformService.changStatue(oid);
    }

    @GetMapping("/getMore")
    @Operation(summary = "通过订单编号获得详细信息")
    public List<OrderIdAndProduct> getMore(@RequestParam int id){
        return orderformService.getMore(id);
    }

    @GetMapping("/getOrder/{oid}")
    @Operation(summary = "通过订单id查找未完成的订单")
    public List<Ordered> getOrder(@PathVariable int oid){
        return orderformService.getOrderedAForm(oid);
    }

    @PutMapping("/addOrder")
    @Operation(summary = "结账")
    public int addOrder(@RequestBody List<Orders> orders , @RequestParam Integer totalnum , @RequestParam Double total, @RequestParam String remarks ,@RequestParam Integer cid){

//        boolean c = orderformService.addOrder(orders , totalnum , total,remarks) > 0;
        return  orderformService.addOrder(orders , totalnum , total,remarks,cid) ;
    }

}
